我要用C#写一个程序,取<A>取这里之间的字符,怎么取呢</A>

来源:百度知道 编辑:UC知道 时间:2024/07/06 15:19:48
我要用C#写一个程序,
取<A href="网址">取这里之间的字符,怎么取呢</A>

Regex.Match(inputString,"(?<=<a.+?>).+?(?=</a>)",RegexOptions.IgnoreCase).Value

说的有点不是很清楚,正常可以用正则表达式

string html = "你的包含<a>的html代码字符串";

string pattern = @"<a[^>]+href=\s*(?:'(?<href>[^']+)'|""(?<href>[^""]+)""|(?<href>[^>\s]+))\s*[^>]*>(?<text>.*?)</a>";

System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.MatchCollection mc = re.Matches(html);
foreach (System.Text.RegularExpressions.Match m in mc)
{
MessageBox.Show(String.Format("{0}:{1}", m.Groups["href"].Value, m.Groups["text"].Value));
}

using System.Xml.Linq;

static v